package cn.lianyutiantang.websocket.service;


import cn.lianyutiantang.websocket.config.WebSocketServer;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class SysWebSocketServer  {

    /**
     * 群发消息内容
     * @param message
     * @return
     */

    public Object sendAll( String message) {
        try {
            WebSocketServer.BroadCastInfo(message);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "ok";
    }
    /**
     * 指定会话ID发消息
     * @param message 消息内容
     * @param id 连接会话ID
     * @return
     */

    public Object sendOne( String message,String id) {
        try {
            WebSocketServer.SendMessage(id,message);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "ok";
    }
}
